package com.huilian.iotbox.data.enums;

import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.stream.Stream;


@Getter
public enum DeviceItemPositionEnum {
    _1(1, 6, ""),
    _2(2, 2, ""),
    _3(3, 3, ""),
    _4(4, 5, ""),
    ;

    private Integer code;
    private Integer positionId;
    private String desc;

    public static Integer getPositionId(Integer value) {
        return Stream.of(DeviceItemPositionEnum.values())
                .filter(p -> p.code.equals(value))
                .findAny()
                .orElse(null).positionId;
    }

    public static Integer getHierarchy(Integer value) {
        final DeviceItemPositionEnum deviceItemPositionEnum = Stream.of(DeviceItemPositionEnum.values())
                .filter(p -> p.positionId.equals(value))
                .findAny()
                .orElse(null);
        if (StringUtils.isEmpty(deviceItemPositionEnum)) {
            return null;
        }
        return deviceItemPositionEnum.code;
    }

    DeviceItemPositionEnum(Integer code, Integer positionId, String desc) {
        this.code = code;
        this.positionId = positionId;
        this.desc = desc;
    }
}
